<%--                                                                       --%>
<%-- Copyright (c) 2005 BroadVision, Inc.  All rights reserved.            --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>

<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>

<% 
  String ctxPath = request.getContextPath();
%>

<script language="JavaScript" src="<%= ctxPath %>/ep/js/block.js" type="text/javascript"></script>
      
<script language="JavaScript">

//
//
//
function saveLayout(){
  if (typeof g_page == "undefined" || g_page == null) {
    alert('<bean-el:message key="ep.block.layout.nosave" bundle="ep.messages"/>');
    return false;
  }

  var inputString = g_page.getBlockLayout();
  if (inputString == null || inputString == "") {
    alert('<bean-el:message key="ep.block.layout.error" bundle="ep.messages"/>');
    return false;
  }
  document.epBlockLayoutForm.blockLayoutString.value = inputString;
  document.epBlockLayoutForm.submit();
  return false;
}

//
//
//
function doReset(form) {
  form.action = "<c:url value="/ep/blockLayoutEdit.do"/>";
  form.submit();
}

//
//
//
function doCancel(form) {
  form.action = "<c:url value="/ep/blockLayoutView.do"/>";
  form.submit();
}

g_btnMaximize.imagePath = "<%= ctxPath %>" + g_btnMaximize.imagePath;
g_btnMinimize.imagePath = "<%= ctxPath %>" + g_btnMinimize.imagePath;
g_btnRestore.imagePath = "<%= ctxPath %>" + g_btnRestore.imagePath;
g_btnClose.imagePath = "<%= ctxPath %>" + g_btnClose.imagePath;
g_btnEdit.imagePath = "<%= ctxPath %>" + g_btnEdit.imagePath;
g_btnUp.imagePath = "<%= ctxPath %>" + g_btnUp.imagePath;
g_btnDown.imagePath = "<%= ctxPath %>" + g_btnDown.imagePath;
g_btnLeft.imagePath = "<%= ctxPath %>" + g_btnLeft.imagePath;
g_btnRight.imagePath = "<%= ctxPath %>" + g_btnRight.imagePath;
g_btnSysMenu.imagePath = "<%= ctxPath %>" + g_btnSysMenu.imagePath;

g_btnMinimize.imageText = "<bean-el:message key="image.alt.collapse" bundle="ep.messages"/>";
g_btnRestore.imageText = "<bean-el:message key="image.alt.expand" bundle="ep.messages"/>";
g_btnClose.imageText = "<bean-el:message key="ep.image.alt.block.hide" bundle="ep.messages"/>";
g_btnEdit.imageText = "<bean-el:message key="image.alt.edit" bundle="ep.messages"/>";

</script>

<c:set var="numColumns" value="${epBlockLayoutView.map.numberOfColumns}" scope="page"/>
<c:set var="totalBlocks" value="0" scope="page"/>

<c:forEach var="column" items="${epBlockLayoutView.map.columns}" varStatus="status" >
  <bean-el:size id="numBlocks" name="column"/>
  <c:set var="totalBlocks" value="${totalBlocks + numBlocks}" scope="page"/>
</c:forEach>

<c:set var="colHeight" value="${totalBlocks * 45}" scope="page"/>
<c:if test="${colHeight < 300}">
  <c:set var="colHeight" value="300"/>
</c:if>

<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="content area">
  <tr>
    <td valign="top" width="100%">
      <div class="pageTitle">
        <bean-el:message key="ep.page.type.edit.page.title" arg0="${epBlockLayoutView.map.name}" bundle="ep.messages"/>
      </div>
      <div class="errorMessage"><html-el:errors bundle="ep.messages"/></div>
      <%@ include file="/mc/common/pagetab.jsp" %>
      <div class="pageSubtitle">
        <span class="left">
          <bean-el:message key="ep.block.layout" bundle="ep.messages"/>
        </span>
        <span class="right">&nbsp;</span>
      </div> 

      <table class="labelForm" width="100%" border="0" cellspacing="0" cellpadding="0" summary="block layout">
        <tr>
        <c:choose>
          <c:when test="${numColumns == 1}" >
            <%@ include file="/ep/block/blockLayoutOneColumn.jsp" %>
          </c:when>
          <c:when test="${numColumns == 2}" >
            <%@ include file="/ep/block/blockLayoutTwoColumn.jsp" %>
          </c:when>
          <c:when test="${numColumns == 3}" >
            <%@ include file="/ep/block/blockLayoutThreeColumn.jsp" %>
          </c:when>
        </c:choose>
        </tr>
      </table>

      <html-el:form action="/ep/blockLayoutSave.do">
      <input type="hidden" name="blockLayoutString" value="">
      <html-el:hidden property="pageTypeId" value="${epBlockLayoutView.map.pageTypeId}"/>
      <html-el:hidden property="numCols" value="${epBlockLayoutView.map.numberOfColumns}"/>

      <div class="pageButtonWrap" align="right">
        <input type="button" name="cancelData" class="inputButton" value="<bean-el:message key="button.reset" bundle="ep.messages"/>" onclick="doReset(this.form);">
        &nbsp;&nbsp;
        <input type="button" name="actionCancel" class="inputButton" value="<bean-el:message key="button.cancel" bundle="ep.messages"/>" onclick="doCancel(this.form);">
        <input type="button" name="saveData" class="inputButton" value="<bean-el:message key="button.save" bundle="ep.messages"/>" onClick="saveLayout();">
      </div>

      </html-el:form>

    </td>
  </tr>
</table>

<script language="JavaScript">

Color.setColors("", "","#FFFFFF");

<c:forEach var="var" items="${epBlockLayoutView.map.columns}" varStatus="status" >
  g_page.addColumn("col<c:out value="${status.index}"/>");
</c:forEach>

</script>

<c:forEach var="column" items="${epBlockLayoutView.map.columns}" varStatus="status">
  <c:set var="columnIndex" value="${status.index}"/>
  <c:set var="column" value="${column}" scope="page"/>

  <c:forEach var="blockLink" items="${column}">
    <c:set var="block" value="${blockLink.block}" scope="page"/>
    <c:set var="blockId" value="${block.id}" scope="page"/>
    <c:choose>
      <c:when test="${blockId < 0}">
        <c:set var="blockStyle" value="BS_REQUIRED & ~BS_MOVEABLE" scope="page"/>
        <c:set var="blockId" value="${-block.id}" scope="page"/>
      </c:when>
      <c:when test="${blockLink.blockType == 2}">
        <c:set var="blockStyle" value="BS_REQUIRED" scope="page"/>
      </c:when>
      <c:otherwise>
        <c:set var="blockStyle" value="BS_DEFAULT" scope="page"/>
      </c:otherwise>
    </c:choose>
 
    <script>
    //Start block
    openBlock("<c:out value="${block.name}"/>");
    </script>
    
    <table cellspacing="0" cellpadding="0" border="0" width="100%">
      <tr>
	<td></td>
      </tr>	
    </table>

    <script>
    //End block
    document.write(closeBlock());
    g_page.createBlock(<c:out value="${blockId}"/>, <c:out value="${columnIndex}"/>, 0, <c:out value="${blockStyle}" escapeXml="false"/>, "#", true );
    </script>
  </c:forEach>
</c:forEach>
</div>
